#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int vis[100][100];
int a[8][8];
int C[10];
int max_, tot;

void search_(int cur)
{
    int i, j;
    if (cur == 8)
    {
        int ans = 0;
        tot++;
        for (int k = 0; k < 8; k++)
        {
            ans += a[k][C[k]];
        }
        if (ans > max_)
            max_ = ans;
    }
    else for (i = 0; i < 8; i++)
    {
        if (!vis[0][i] && !vis[1][cur + i] && !vis[2][cur - i + 8])
        {
            C[cur] = i;
            vis[0][i] = vis[1][cur + i] = vis[2][cur - i + 8] = 1;
            search_(cur + 1);
            vis[0][i] = vis[1][cur + i] = vis[2][cur - i + 8] = 0;
        }
    }
}

int main()
{
    int t;
    scanf("%d", &t);
    while (t--)
    {
        for (int i = 0; i < 8; i++)
        {
            for (int j = 0; j < 8; j++)
            {
                scanf("%d", &a[i][j]);
            }
        }
        max_ = -1;
        tot = 0;
        memset(vis, 0, sizeof(vis));
        search_(0);
        printf("tot = %d\n", tot);
        printf("%5d\n", max_);
    }
    return 0;
}